package Dao.impl;

import Dao.BaseDao;
import Dao.UserDao;
import Entity.User;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

public class UserDaoimpl extends BaseDao implements UserDao {
    private Connection conn;
    private PreparedStatement pre;
    private ResultSet rs;
    @Override
    public User login(User user) {
        try {
            conn=super.getConnection();
            String sql="select * from petowner where name=? and password=?";
            pre=conn.prepareStatement(sql);
            pre.setObject(1,user.getName());
            pre.setObject(2,user.getPassword());
            rs=pre.executeQuery();
            User userLogin=null;
            if (rs.next()){
                userLogin=new User();
                userLogin.setName(rs.getString("name"));
                userLogin.setPassword(rs.getString("password"));
            }
            return userLogin;
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }


}
